package com.xuxin.baby.model;

import com.xuxin.baby.bean.BaseBean;
import com.xuxin.baby.contract.TestContract;
import com.xuxin.baby.network.Retrofit;
import com.xuxin.baby.network.RetrofitApi;
import com.xuxin.baby.network.myObserver;
import com.xuxin.baby.presenter.TestPresenter;

import org.json.JSONException;
import org.json.JSONObject;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.observers.DisposableObserver;
import io.reactivex.rxjava3.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by xu_xin
 * Created on 2020/10/22 0022
 * 测试
 */
public class TestModel implements TestContract.Model {

    @Override
    public void test(TestPresenter presenter, String tenantId, String token) {
        try {
            JSONObject object = new JSONObject();
            object.put("memberId", 41);
            object.put("couponId", "5fd8173f-8963-4c69-fbff-08d890e9eb0d");
            RequestBody requestBody = RequestBody.create(object.toString(), MediaType.parse("application/json"));
            Retrofit.getInstance().createReq(RetrofitApi.class)
                    .test(tenantId, token,"1", requestBody)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new myObserver<BaseBean>() {
                        @Override
                        public void onNextX(@NonNull BaseBean baseBean) {
                        }

                        @Override
                        public void onError(@NonNull Throwable e) {
                        }
                        @Override
                        public void onError(BaseBean baseBean) {

                        }
                        @Override
                        public void onComplete() {
                        }
                    });
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}